using System.Collections.Generic;
using System.Collections;
using System;

namespace Box.Base {
        public class StorageFileWriteError : Exception {
        public StorageFileWriteError(string msg):base(msg) {}
    }

    public class StorageFileReadError : Exception {
        public StorageFileReadError(string msg):base(msg) {}
    }

    public enum StorageFileMode {
        Write,
        Read,
    }

    public enum StorageItemType {
        Label = 0,
        Undefined,//空值
        Int,//整型数字类型
        Float,//浮点数字类型
        String,//字符串类型
        Boolean,//布尔类型
        Array,//数组 Array<T>
        Hashtable,//哈希表 Hashtable<string,Any>
        AnyArray,//多类型数组 Array<Any>
        Object,//实现了IStorage接口的对象
    }

    public static class StorageFileHelper {
        public static bool IsStorageType(object value) {
            return 
                value is Int16      ||
                value is Int32      ||
                value is Int64      ||
                value is UInt16     ||
                value is UInt32     ||
                value is UInt64     ||
                value is Byte       ||
                value is Boolean    ||
                value is float      ||
                value is double     ||
                value is string     ||
                value is ArrayList  ||
                value is Hashtable  ||
                value is IStorage   ||
                value is Array      ;
        }
    }

    public interface IStorageFile {
        bool Open(string path,StorageFileMode mode);
        void Close();
        void Flush();

        /*单纯的写入和读取*/
        void Write(int value);
        void Write(double value);
        void Write(string value);
        void Write(bool value);
        void Write(Array values);
        void Write(ArrayList values);
        void Write(Hashtable values);
        void Write(IStorage value);
        int ReadInt();
        double ReadFloat();
        string ReadString();
        bool ReadBoolean();
        Array ReadArray();
        Hashtable ReadHashtable();
        ArrayList ReadAnyArray();
        IStorage ReadStorageObject();
        /*带标签标记的写入和读取*/
        void WriteItem(int value);
        void WriteItem(double value);
        void WriteItem(string value);
        void WriteItem(bool value);
        void WriteItem(Array values);
        void WriteItem(ArrayList values);
        void WriteItem(Hashtable values);
        void WriteItem(IStorage value);
        int TryReadIntItem();
        double TryReadFloatItem();
        string TryReadStringItem();
        bool TryReadBooleanItem();
        Array TryReadArrayItem();
        Hashtable TryReadHashtableItem();
        ArrayList TryReadAnyArrayItem();
        IStorage TryReadStorageItem();
    }
}